﻿<%@ Page Title="" Language="C#" MasterPageFile="~/App_form/Menu/dao_tao.master" AutoEventWireup="true" CodeFile="Tinh.aspx.cs" Inherits="App_form_Danhmuc_Default" %>

<%@ Register TagPrefix="Control" TagName="menu_phai" Src="~/App_ctr/Admin/menu_phai.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <div style="width: 100%">
        <div style="width: 20%; float: left;">
            <Control:menu_phai runat="server" ID="menuphai" />
        </div>
        <div style="width: 79.4%; float: right;">
            <div style="background-image: url(../../CSS/images/ui-bg_glass_75_e6e6e6_1x400.png); font-weight: bold; height: 30px; border: 1px solid #d3d3d3; margin-top: 4px; text-align: center; padding-top: 8px; text-transform: uppercase;">
                Danh mục tỉnh
            </div>
            <div id="ndung" style="padding: 40px; margin-top: 2px;">
                <div style="display: table; margin: 0 auto; width: 70%; border: 1px solid #d3d3d3; font-size: 16px;">
                    <div style="background-image: url(../../Images/Hethong/back.gif); background-repeat: repeat-x; height: 30px; font-size: 12px !important;"></div>
                    <div style="padding: 20px;">
                        <div id="ndung_ct" class="clearfix">
                            <div style="width: 59%; float: left; margin-top: 90px;">
                                <div style="float: left; width: 20%;">
                                    <label>
                                        Mã  :
                                    </label>
                                </div>
                                <div>
                                    <Lib:textBox runat="server" ID="MA" Width="120px" UpperCase="true" Msg="mã tỉnh" onClientChange="P_TINH_CHANG()" />
                                </div>
                                <div style="width: 100%; height: 6px;"></div>
                                <div style="float: left; width: 20%;">
                                    <label>
                                        Tên  :
                                    </label>
                                </div>
                                <div>
                                    <Lib:textBox runat="server" ID="ten" Width="250px" Msg="tên tỉnh" />
                                </div>
                            </div>
                            <div style="width: 40%; float: left;">
                                <Lib:gridView runat="server" ID="lke_tinh" Width="270" Height="250" onClientCellClick="TINH_CELL_CLICK">
                                    <Columns>
                                        <Lib:Column BaseColumn="MA" Name="Mã" Width="70" />
                                        <Lib:Column BaseColumn="TEN" Name="Tên" Width="180" />
                                    </Columns>
                                    <Pager>
                                        <Lib:Pager PageSize="9" />
                                    </Pager>
                                </Lib:gridView>
                            </div>
                        </div>
                        <div style="width: 100%; height: 30px;"></div>
                        <div style="margin-left: 100px;">
                            <Lib:Button runat="server" ID="add" Text="Thêm mới" Width="100px" onClientClick="P_TINH_NH()"></Lib:Button>
                            <Lib:Button runat="server" ID="new" Text="Mới" Width="100px" onClientClick="P_TINH_MOI()"></Lib:Button>
                            <Lib:Button runat="server" ID="del" Text="Xóa" Width="100px" onClientClick="P_TINH_XOA()"></Lib:Button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <asp:HiddenField ID="kthuoc" runat="server" Value="0,0" />
    <script>
        //TIM
        function P_TINH_CHANG() {
            try {
                var ma = $("#<%=MA.ClientID%>").val();
                var grid = GetGridByID("<%=lke_tinh.ClientID%>");
                var b_hang = grid.getRowIndex(["MA"], [ma], ["=="]);
                if (b_hang >= 0) {
                    grid.setActiveRow(b_hang);
                    var ten = grid.getValue(b_hang, ["TEN"]).TEN;
                    $("#<%=ten.ClientID%>").val(ten);
                }
            }
            catch (e) {
                ShowError(e.message);
            }
        }

        //NHAP
        function P_TINH_NH() {
            try {
                var ma = $("#<%=MA.ClientID%>").val(), ten = $("#<%=ten.ClientID%>").val();
                wht_nsd.FDM_TINH_NH(ma, ten, P_TINH_NH_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (e) {
                Msg.Show("Thông báo", e.message, "error");
            }
        }

        function P_TINH_NH_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var grid = GetGridByID("<%=lke_tinh.ClientID%>");
            grid.dataBin(b_kq);
            var ma = $("#<%=MA.ClientID%>").val()
            var b_hang = grid.getRowIndex(["MA"], [ma], ["=="]);
            if (b_hang >= 0)
                grid.setActiveRow(b_hang);
        }

        //MỚI
        function P_TINH_MOI() {
            ResetForm("ndung_ct");
        }


        //XÓA
        function P_TINH_XOA() {
            try {
                var ma = $("#<%=MA.ClientID%>").val();
                if (ma == "") {
                    Msg.ShowError(e.message);
                    return;
                }
                wht_nsd.FDM_TINH_XOA(ma, P_TINH_XOA_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (e) {
                ShowError(e.message);
            }
        }
        function P_TINH_XOA_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var grid = GetGridByID("<%=lke_tinh.ClientID%>");
            grid.dataBin(b_kq);
            var ma = $("#<%=MA.ClientID%>").val()
            var b_hang = grid.getRowIndex(["MA"], [ma], ["<"]);
            if (b_hang >= 0)
                grid.setActiveRow(b_hang);
        }

        //ACTIVE ROW
        function TINH_CELL_CLICK(row, cell, val) {
            try {
                var grid = GetGridByID("<%=lke_tinh.ClientID%>");
                var aVal = grid.getValueActive(["MA", "TEN"]);
                if (aVal.MA == "")
                    return;
                $("#<%=MA.ClientID%>").val(aVal.MA);
                $("#<%=ten.ClientID%>").val(aVal.TEN);
            }
            catch (e)
            { Msg.Show("Thông báo", e.message, "error"); }
        }

    </script>
</asp:Content>

